import 'package:flutter/material.dart'; 
import 'package:cached_network_image/cached_network_image.dart'; 
 
class CachedImage extends StatelessWidget {
  final String imageUrl; // 网络图片 URL 
  final double? width; // 图片宽度 
  final double? height; // 图片高度 
  final BoxFit? fit; // 图片填充方式 
  final String placeholderPath; // 占位符图片路径 
 
  const CachedImage({
    Key? key,
    required this.imageUrl, 
    this.width, 
    this.height, 
    this.fit, 
    this.placeholderPath  = 'assets/images/placeholderImage.png',  // 默认占位符 
  }) : super(key: key);
 
  @override 
  Widget build(BuildContext context) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(10),  // 设置圆角为 10 
      child: CachedNetworkImage(
        imageUrl: imageUrl,
        width: width,
        height: height,
        fit: fit,
        placeholder: (context, url) => Image.asset( 
          placeholderPath,
          width: width,
          height: height,
          fit: fit,
        ),
        errorWidget: (context, url, error) => Image.asset( 
          placeholderPath,
          width: width,
          height: height,
          fit: fit,
        ),
      ),
    );
  }
}